<template>
<div class="panel">
    <div class="panel-header">
        <div class="bl"></div>
        <div class="title">品牌</div>
        <div class="more">
            <el-form v-model="ruleForm" inline class="my-form">
                <el-form-item>
                    <picker-view v-model="ruleForm.brand_id" type="company" placeholder="请选择品牌"></picker-view>
                </el-form-item>
                
                <el-form-item>
                    <el-button type="primary" @click="doAppendBrand">添加</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
    <div class="panel-body">
        <el-table :data="brandList" border>
            <el-table-column label="品牌" prop="brand.title"></el-table-column>
            <el-table-column label="添加人" prop="user.realname"></el-table-column>
            <el-table-column label="分配状态" width="120">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.is_assign == '0'" type="danger">未分配</el-tag>
                    <el-tag v-else type="success">已分配</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="获取时间" prop="create_time" width="130"></el-table-column>
        </el-table>
    </div>
</div>
</template>

<script>
import {
    doCreateBrandApi,
    doDeleteBrandApi
} from '@/api/customer/brand'
import pickerView from '@/components/picker/select.vue'
export default {
    name: "CustomerBrands",
    components: {
        pickerView
    },
    props: {
        brandList: {
            type: Array,
            default: []
        },
        allocate: {
            id: "",
            member_id: "",
            sign_time: "",
        }
    },
    data() {
        return {
            ruleForm: {
                member_id: "",
                brand_id: ""
            }
        }
    },
    methods: {
        doAppendBrand() {
            // model 提示
            if (!this.ruleForm.brand_id) {
                this.$message.error('请选择品牌')
                return
            }

            // 确认提示
            this.$confirm('确定要添加该品牌吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.ruleForm.member_id = this.allocate.member_id
                doCreateBrandApi(this.ruleForm).then(res => {
                    this.$message.success('添加成功')
                    this.$emit('refresh')
                })
            }).catch(() => {
                this.$message.info('已取消')
            })
        }
    }
}
</script>

<style lang="less" scoped>
.my-form {
    .el-form-item {
        margin-bottom: 0;
    }
}
</style>
